package com.example.purplestarcb.shoujizhushou;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Setup3Activity extends BaseSetupActivity {
    private EditText editPhoneNumber;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setup3);
        editPhoneNumber= (EditText) findViewById(R.id.edit_phone_numbr);

    }

    @Override
    public void showNext() {
        String phone = editPhoneNumber.getText().toString().trim();
        if(TextUtils.isEmpty(phone)){
            Toast.makeText(this, "安全号码还没有设置", 0).show();
            return;
        }


        //应该保持一些 安全号码
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("safenumber", phone);
        editor.apply();


        Intent intent = new Intent(this,Setup4Activity.class);
        startActivity(intent);
        finish();
        //要求在finish()或者startActivity(intent);后面执行；
        overridePendingTransition(R.anim.tran_in, R.anim.tran_out);

    }

    @Override
    public void showPre() {
        Intent intent = new Intent(this,Setup2Activity.class);
        startActivity(intent);
        finish();
        //要求在finish()或者startActivity(intent);后面执行；
        overridePendingTransition(R.anim.tran_pre_in, R.anim.tran_pre_out);

    }

    public void succeedContact(View view){
        String phone = editPhoneNumber.getText().toString().trim();
        if(TextUtils.isEmpty(phone)){
            Toast.makeText(this, "安全号码还没有设置", 0).show();
            return;
        }


        //应该保持一些 安全号码
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("safenumber", phone);
        editor.apply();


        Intent intent = new Intent(this,Setup4Activity.class);
        startActivity(intent);
        finish();
        //要求在finish()或者startActivity(intent);后面执行；
        overridePendingTransition(R.anim.tran_in, R.anim.tran_out);
    }


    /**
     * 选择联系人的点击事件
     * @param view
     */
    public void selectContact(View view){
        Intent intent = new Intent(this,SettingContectActivity.class);
        startActivityForResult(intent, 0);

    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if(data == null)
            return;

        String phone = data.getStringExtra("phone").replace("-", "");
        Log.i("console",""+phone);
        editPhoneNumber.setText(phone);

    }
}
